<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // var googleMap = {
        //     show: function () {
        //         console.log(1)
        //     }
        // }
        // var baiduMap = {
        //     display: function () {
        //         console.log(1)
        //     }
        // }


        // var rendMap = function (map) {
        //     if (map.show instanceof Function) {
        //         map.show()
        //     }
        // }

        // var baiduMapAdapter = {
        //     show: function () {
        //         return baiduMap.display()
        //     }
        // }
        // rendMap(googleMap)
        // rendMap(baiduMapAdapter)



        var getBeijingCity = function () {
            var beijingCity = [
                { name: 'chaoyang', id: 11 },
                { name: 'haidian', id: 12 },
            ]
            return beijingCity
        }

        var render = function (fn) {
            console.log('渲染北京地图')
            console.log(JSON.stringify(fn()))
        }

        // render(getBeijingCity)

        var addressAdapter = function (oldAddress) {
            var address = {},
                oldAddress = oldAddress(),
            item

            for (let i = 0; i < oldAddress.length; i++) {
                item = oldAddress[i]
                address[item.name] = item.id
            }
            return function () {
                return address
            }
        }

        render(addressAdapter(getBeijingCity))

    </script>
</body>

</html>